package com.michaelbulava.TFS.vcs.internal;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.FilePath;
import com.michaelbulava.TFS.log.FileLogger;
import com.michaelbulava.TFS.vcs.TFSVcs;
import com.michaelbulava.TFS.vcs.utils.TFSFileUtil;
import com.microsoft.tfs.core.clients.versioncontrol.GetItemsOptions;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.DeletedState;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ExtendedItem;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.ItemType;
import com.microsoft.tfs.core.clients.versioncontrol.soapextensions.Workspace;
import com.microsoft.tfs.core.clients.versioncontrol.specs.ItemSpec;
import com.microsoft.tfs.util.Check;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by MichaelA on 9/3/2015.
 */
public abstract class AbstractStatusProvider {
    protected static final Logger log = FileLogger.getInstance(AbstractStatusProvider.class);

    public void vistByStatus(Project project, Workspace workspace, List<FilePath> roots, boolean recursive,
                             StatusVisitor statusVisitor, ProgressIndicator indicator){
        Check.notNull(project, "project");
        Check.notNull(workspace, "workspace");
        Check.notNull(statusVisitor, "statusVisitor");

        ItemSpec[] itemSpecs = TFSFileUtil.getItemSpecs(project, workspace, roots, recursive, false);
        if (itemSpecs.length == 0)
            return;

        Map<FilePath, ExtendedItem> extendedItemMap = new HashMap<FilePath, ExtendedItem>();

        if (TFSVcs.getInstance(project).isWorkspaceOnline(workspace)){
            ExtendedItem[][] items = workspace.getExtendedItems(itemSpecs, DeletedState.ANY, ItemType.ANY,
                    GetItemsOptions.combine(new GetItemsOptions[] {
                            GetItemsOptions.INCLUDE_BRANCH_INFO,
                            GetItemsOptions.INCLUDE_RECURSIVE_DELETES,
                            GetItemsOptions.INCLUDE_BRANCH_INFO
                    }));
        }
    }
}
